//! @Author: DengLibin
//! @Date: Create in 2024-07-17 12:33:47
//! @Description:

use crate::sys::global::GlobalResult;
use serde::{Deserialize, Serialize};

pub mod controller;
pub mod midware;
pub mod router;

//接口响应数据格式
#[derive(Debug, Serialize, Deserialize)]
pub struct Resdata<T> {
    pub status_code: i16,
    pub status_msg: String,
    pub data: Option<T>,
}

impl<T> Resdata<T> {
    pub fn ok_result(result: GlobalResult<T>) -> Self {
        return match result {
            Ok(t) => Resdata {
                status_code: 200,
                status_msg: "".into(),
                data: Some(t),
            },
            Err(err) => Resdata {
                status_code: -1,
                status_msg: err.to_string(),
                data: None,
            },
        };
    }
    pub fn ok(msg: String) -> Self {
        Resdata{
            status_code: 200,
            status_msg: msg,
            data: None,
        }
    }
    #[allow(dead_code)]
    pub fn ok_data(msg: String, data: T) -> Self {
        Resdata{
            status_code: 200,
            status_msg: msg,
            data: Some(data),
        }
    }
    pub fn err(msg: String) -> Self {
        Resdata{
            status_code: -1,
            status_msg: msg,
            data: None,
        }
    }
}
